/**
 * @file thread_queue_test.cpp
 * @date 2021/11/01 20:11
 *
 * @author harrybao (harrybao@123u.com)
 *
 * @brief 测试线程池
 *
 * @version v1.0.0
 *
 * @copyright Copyright © 2021 harrybao All Rights Reserved
 *
 * @par history:
 * <table>
 * <tr><th>Date                     <th>Version     <th>Author <th>Description
 * <tr><td>2021/11/01 20:11         <td>1.0.0       <td>harrybao
 * <td>创建初始版本
 * </table>
 */

#include <functional>
#include <iostream>

#include "tests/unit/unit_test.hpp"
#include "thread/pool/thread_pool.hpp"

void test_thread_queue() {
  // TEST_CHECK(true);
  using func_type = std::function<void()>;
  hthread::thread_pool<func_type, 128> pool;
  pool.init();

  std::vector<std::future<std::string>> result_vec;
  for (int i = 0; i < 1000000; ++i) {
    auto task = [i]() -> std::string {
      // std::this_thread::sleep_for(std::chrono::milliseconds(100));
      // std::cout << "(i:" << i << ")" << '\n';
      return "completed";
    };

    auto result = pool.submit(task);
    result_vec.emplace_back(std::move(result));
  }

  // std::this_thread::sleep_for(std::chrono::milliseconds(1000));

  std::cout << result_vec.back().get() << '\n';
}

int main() {
  TEST_CASE(test_thread_queue);
  return 0;
}